<!DOCTYPE html>
<html lang="cn" xmlns:th="http://www.thymeleaf.org">
<head th:replace="~{_fragments::common_header(~{::title})}">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>用户管理 - 逍遥论坛</title>
<link href="../../static/css/bootstrap.min.css"
	th:href="@{/static/css/bootstrap.min.css}" rel="stylesheet">
<script src="../../static/js/jquery-3.2.1.js"
	th:src="@{/static/js/jquery-3.2.1.js}"></script>
<script src="../../static/js/bootstrap.min.js"
	th:src="@{/static/js/bootstrap.min.js}"></script>
<style>
li {
	list-style-type: none;
}

html, body {
	height: 100%;
	font-size: 14px;
	color: #525252;
	font-family: NotoSansHans-Regular, AvenirNext-Regular, arial,
		Hiragino Sans GB, "Microsoft Yahei", "Hiragino Sans GB",
		"WenQuanYi Micro Hei", sans-serif;
	background: #f0f2f5;
}

.footer {
	background-color: #fff;
	margin-top: 22px;
	margin-bottom: 22px;
	width: 100%;
	padding-top: 22px;
	color: #8A8A8A;
	display: block;
	height: 200px;
	border: 1px;
	clear: both
}

.container {
	margin-right: 5%;
	margin-left: 5%;
	padding-left: 15px;
	padding-right: 15px;
	width: 40%;
	float: left;
}

a {
	color: #8A8A8A;
	cursor: pointer;
}

th {
	text-align: center; /*设置水平居中*/
	/* vertical-align:middle; */ /*设置垂直居中*/
}

td {
	text-align: center; /*设置水平居中*/
	/* vertical-align:middle; */ /*设置垂直居中*/
	/* border: 1px solid gray; */
}
</style>
</head>
<body>

	<!-- 引入header文件 -->
	<header th:replace=" _fragments:: header"></header>

	<div class="panel panel-default"
		style="width: 90%; margin-left: 5%; margin-right: 5%; margin-bottom: 5%">
		<div class="panel-heading" style="background-color: #fff">
			<h3 class="panel-title">用户管理</h3>
		</div>
		<div class="panel-body">

			<!-- 这里显示所有用户信息 -->
			<table class="table">
				<thead>
					<tr>
						<th>用户ID</th>
						<th>用户名</th>
						<th>用户昵称</th>
						<th>用户权限</th>
						<th>状态</th>
						<th>操作</th>
					</tr>
				</thead>
				<tbody>
					<!-- 这里是表格内容，需要遍历数组 -->
					<c:forEach items="${users}" var="user">
						<tr th:each="user,iterStat: ${users}">
							<td th:text="${user.userId}">${user.user_id}</td>
							<td th:text="${user.userName}">${user.user_name}</td>
							<td th:text="${user.userNick}">${user.user_nick}</td>
							<td th:switch="${user.userType}"><span th:case="0">超级管理员</span>
								<span th:case="1">管理员</span> <span th:case="*">普通用户</span> <!-- <c:choose>
                                <c:when test="${user.user_type == 0}">超级管理员</c:when>
                                <c:when test="${user.user_type == 1}">管理员</c:when>
                                <c:otherwise>普通用户</c:otherwise>
                            </c:choose>-->
							<td th:switch="${user.userStatus}"><span th:case="1">禁用</span>
								<span th:case="2">锁定</span> <span th:case="*">正常</span> <!--  <c:choose>
                                <c:when test="${user.user_status == 1}">禁用</c:when>
                                <c:when test="${user.user_status == 2}">锁定</c:when>
                                <c:otherwise>正常</c:otherwise>
                            </c:choose> --></td>
							<td th:switch="${user.userStatus}">
								<!-- 这里放操作按钮 -->
								<div th:case="1">
									<a type="button" class="btn btn-success"
										th:href="'enableUser.do?userId='+${user.userId}">启用</a> <a
										type="button" class="btn btn-warning"
										th:href="'lockUser.do?userId='+${user.userId}">锁定</a>
								</div>
								<div th:case="2">
									<a type="button" class="btn btn-success"
										th:href="'enableUser.do?userId='+${user.userId}">解锁</a> <a
										type="button" class="btn btn-danger"
										th:href="'disableUser.do?userId='+${user.userId}">禁用</a>
								</div>
								<div th:case="*" th:if="${user.userId != session.user.userId}">
									<div th:switch="${session.user.userType}">
										<div th:case="1" th:if="${user.userType==2}">

											<!-- 处理其它正常的用户：管理员不能处理自己的状态 -->

											<!-- 管理员不能处理其它管理员 -->

											<!-- 管理员可处理普通用户 -->

											<a type="button" class="btn btn-warning"
												th:href="'toUpdateUserInfoPage.do?userId='+${user.userId}">修改</a>
											<a type="button" class="btn btn-danger"
												th:href="'disableUser.do?userId='+${user.userId}">禁用</a> <a
												type="button" class="btn btn-warning"
												th:href="'lockUser.do?userId='+${user.userId}">锁定</a>

										</div>
											<!-- 超级管理员权限：超级管理员不能处理其它超级管理员 -->
											<div th:case="0">
												<div th:if="${user.userType!=0}">
													<div th:switch="${user.userStatus}">
														<a type="button" class="btn btn-warning"
												th:href="'toUpdateUserInfoPage.do?userId='+${user.userId}">修改</a>
														<span th:case="1"> <a type="button"
															class="btn btn-success"
															th:href="'enableUser.do?userId='+${user.userId}">启用</a> <a
															type="button" class="btn btn-warning"
															th:href="'lockUser.do?userId='+${user.userId}">锁定</a>
														</span> <span th:case="2"> <a type="button"
															class="btn btn-success"
															th:href="'enableUser.do?userId='+${user.userId}">解锁</a> <a
															type="button" class="btn btn-danger"
															th:href="'disableUser.do?userId='+${user.userId}">禁用</a>
														</span> <span th:case="*"> <a type="button"
															class="btn btn-warning"
															th:href="'lockUser.do?userId='+${user.userId}">锁定</a> <a
															type="button" class="btn btn-danger"
															th:href="'disableUser.do?userId='+${user.userId}">禁用</a>
														</span>
													</div>

													<!-- 如果对方是超级管理员 无操作 -->


												</div>
											</div>
									</div>
								</div>
							</td>
						</tr>
					</c:forEach>
				</tbody>
			</table>
			<a type="button" class="btn btn-default"
				style="margin-left: 20%"
				th:href="toMainPage.do">返回</a>
		</div>
	</div>

	<!-- 引入footer文件 -->
	<footer th:replace="_fragments:: footer"></footer>

</body>
</html>